"""
统一响应格式
"""
from typing import Any, Optional
from pydantic import BaseModel


class ApiResponse(BaseModel):
    """API统一响应格式"""
    code: int
    message: str
    data: Optional[Any] = None


def success_response(data: Any = None, message: str = "success") -> dict:
    """
    成功响应
    
    Args:
        data: 响应数据
        message: 响应消息
    
    Returns:
        响应字典
    """
    return {
        "code": 200,
        "message": message,
        "data": data
    }


def error_response(code: int, message: str, data: Any = None) -> dict:
    """
    错误响应
    
    Args:
        code: 错误码
        message: 错误消息
        data: 额外数据
    
    Returns:
        响应字典
    """
    return {
        "code": code,
        "message": message,
        "data": data
    }
